var consoleLogEnabled= true;
var TCGEnabled = false;
var FrameEnabled = true;
function fntest_start(testname)
{
	console.log("******* Start Testing of " + testname + "*******");
}

function fnLog(testResult,nextPage)
{
	var RESULTS ="ERROR";
	if (testResult.pass)
		RESULTS = "SUCCESS";

	if (consoleLogEnabled) {
		console.log(RESULTS+" :" + testResult.description);
	}
	if (TCGEnabled)
	{
		parent.location.href="../../sf_html5Post.asp?RESULTS=" + RESULTS;	
	}
	if (FrameEnabled)
	{
		var TestFrame = top.frames["testFrame"];	
		TestFrame.location.href=nextPage;		
		fnLogResult(RESULTS);
	}
	else
	{
		alert(RESULTS+" :" + testResult.description);		
		parent.location.href=nextPage;
	}
	
}
function fnLogResult(testResult)
{
	var resframe = top.frames["resultFrame"].document;	
	var restable=resframe.getElementById("resulttable").tBodies[0];
	var test = new String(location.href);
	var testId = test .substr(test .lastIndexOf("/")+1 ,test .length);

	if (testResult=="SUCCESS")
	{
		restable.innerHTML += "<tr><td><font color=green>"+testId +"</font></td><td><font color=green>"+testResult+"</font></td></tr>" 
		resframe.getElementById("pass").value= new Number(resframe.getElementById("pass").value)+1;

	}
	else
	{
		restable.innerHTML += "<tr><td><font color=red>"+testId +"</font></td><td><font color=red>"+testResult+"</font></td></tr>" 
		resframe.getElementById("fail").value= new Number(resframe.getElementById("fail").value)+1;

	}
	resframe.getElementById("total").value= new Number(resframe.getElementById("total").value)+1;

	if (consoleLogEnabled) {
                console.log(testId+": " +testResult);
        }

	
}

function fnDisplayResult(testResult,resultdiv,append)
{
//testResult - testResult.Pass =true/ false, testResult.description =description of test result
//resultdiv  - Div object in which the test results has to be displayed
//append - true/ false - if results are to be appended to the current div, or current div to be erased and results are written

	if (testResult.pass)
	{
		if (append) {
			resultdiv.innerHTML += "<font color=green>SUCCESS:" +  testResult.description + "</font><br>";

		}
		else
		{
			resultdiv.innerHTML = "<font color=green>SUCCESS:" +  testResult.description + "</font>";
		}
	}
	else
	{
		if (append) {
			resultdiv.innerHTML += "<font color=red>ERROR:" + testResult.description + "</font><br>";
		}
		else
		{
			resultdiv.innerHTML = "<font color=red>ERROR:" + testResult.description + "</font>";
		}
	}
	
}
function fnClearResult()
{
	var resframe = top.frames["resultFrame"].document;	
	resframe.getElementById('resultdiv').innerHTML="";
	var restable=resframe.getElementById("resulttable"); 
	while(restable.rows.length>=1) 
	{
		restable.deleteRow(restable.rows.length-1);
	}
	resframe.getElementById('pass').value=0;
	resframe.getElementById('fail').value =0;
	resframe.getElementById('total').value =0;

}
function fnShowResultData(test_name)
{
	
      	var resframe = top.frames["resultFrame"].document;
	var passpercent = new Number(resframe.getElementById('pass').value)/new Number(resframe.getElementById('total').value)*100;
	resframe.getElementById('resultdiv').innerHTML="";
	resframe.getElementById('resultdiv').innerHTML+="<br>Total Tests : "+ resframe.getElementById('total').value;
	resframe.getElementById('resultdiv').innerHTML+="<br>Passed: "+ resframe.getElementById('pass').value;
	resframe.getElementById('resultdiv').innerHTML+="<br>Failed : "+ resframe.getElementById('fail').value;
	resframe.getElementById('resultdiv').innerHTML+="<br>Pass% : "+ Math.round(passpercent)+"<br><br>";
	var total = resframe.getElementById('total').value;
	var pass = resframe.getElementById('pass').value;
	var fail = resframe.getElementById('fail').value;
	var skip = total - pass - fail;

      console.log("Testsuite total case number: "+total);
	console.log("Totals: "+pass+" passed, "+fail+" failed, "+skip+" skipped");
      console.log("******* Finished Testing of "+test_name+"*******");
	top.document.getElementById('end').value=1;
}
function fnAddHeader(str)
{
	var resframe = top.frames["resultFrame"].document;	
	var restable=resframe.getElementById("resulttable").tBodies[0];
	restable.innerHTML += "<tr><td>"+str +"</td></tr>"; 
}